package com.example.utils;

import org.apache.http.HttpStatus;

import java.util.HashMap;
import java.util.Map;

/**
 * 返回数据
 */
public class Result extends HashMap<String, Object> {
	private static final long serialVersionUID = 1L;
	
	public Result() {
		put("code", 200);
		put("msg", "success");
	}
	
	public static Result error() {
		return error(HttpStatus.SC_INTERNAL_SERVER_ERROR, "未知异常，请联系管理员");
	}
	
	public static Result error(String msg) {
		return error(HttpStatus.SC_INTERNAL_SERVER_ERROR, msg);
	}
	
	public static Result error(int code, String msg) {
		Result r = new Result();
		r.put("code", code);
		r.put("msg", msg);
		return r;
	}

	public static Result ok(String msg) {
		Result r = new Result();
		r.put("msg", msg);
		return r;
	}
	
	public static Result ok(Map<String, Object> map) {
		Result r = new Result();
		r.putAll(map);
		return r;
	}
	
	public static Result ok() {
		return new Result();
	}

	public Result put(String key, Object value) {
		super.put(key, value);
		return this;
	}

	public static Result badArgument() {
		return error(401, "参数不对");
	}

	public static Result badArgumentValue() {
		return error(402, "参数值不对");
	}

	public static Result unLogin() {
		return error(501, "请登录");
	}

	public static Result serious() {
		return error(502, "系统内部错误");
	}

	public static Result unSupport() {
		return error(503, "业务不支持");
	}

	public static Result updatedDateExpired() {
		return error(504, "更新数据已经失效");
	}

	public static Result updatedDataFailed() {
		return error(505, "更新数据失败");
	}

	public static Result unAuth() {
		return error(506, "无操作权限");
	}
}
